const { getOrders, deleteOrders, searchOrders, getOrdersById, searchOrdersById, deleteOrdersById
    , addOrder, searchById, changeOrdersState
} = require('../dao/ordersDao')

/*1.管理员 */
//获取订单列表
module.exports.getOrders = async function (orders) {
    //通过订单查询
    if (orders.searchData.searchType || orders.searchData._id || orders.searchData.name || orders.searchData.address || orders.searchData.startTime) {
        const result = await searchOrders(orders);
        return {
            message: "订单数据查询成功",
            status: 1,
            data: result
        }
    } else {
        const result = await getOrders(orders);
        return {
            message: '订单数据获取成功',
            status: 1,
            data: result
        }
    }
}

//删除
module.exports.deleteOrders = async function (_id) {
    const result = await deleteOrders(_id);
    if (result.n) {
        return {
            message: "订单数据删除成功",
            status: 1
        }
    } else {
        return {
            message: "订单数据删除失败",
            status: 0
        }
    }
}


/*出租方 */
//获取订单列表
module.exports.getOrdersById = async function (orders) {
    //通过订单查询
    if (orders.searchData.searchType || orders.searchData._id || orders.searchData.name || orders.searchData.address || orders.searchData.startTime) {
        const result = await searchOrdersById(orders);
        return {
            message: "订单数据查询成功",
            status: 1,
            data: result
        }
    } else {
        const result = await getOrdersById(orders);
        return {
            message: '订单数据获取成功',
            status: 1,
            data: result
        }
    }
}

//删除
module.exports.deleteOrdersById = async function (_id) {
    const result = await deleteOrdersById(_id);
    if (result.n) {
        return {
            message: "订单数据删除成功",
            status: 1
        }
    } else {
        return {
            message: "订单数据删除失败",
            status: 0
        }
    }
}

//新增订单
//新增订单
module.exports.addOrder = async function (code) {
    const result = await addOrder(code);


    return {
        message: "订单成功提交",
        status: 1
    }

}



//通过租客id查找订单
module.exports.searchById = async function (id) {
    const data = await searchById(id);
    return {
        message: "订单成功提交",
        status: 1,
        data
    }

}


//还车位
module.exports.changeOrdersState = async function (id) {
    const data = await changeOrdersState(id);
    return {
        message: "订单成功提交",
        status: 1,
        data
    }

}


